"""
    从一幅图片中提取所隐藏的黑白图片
    输入：
        含水印图片
        提取的图片尺寸
    输出：
        一幅二值图片
"""
import sys
import numpy as np
from cv2 import cv2
import extrac
from PicHide import std # 阈值标准

def printHelp():
    print("Help Usage:python {} [含图片水印图片] [解密密钥Key] [提取的图片的像素高] [提取的图片的像素高] [提取出的图片带后缀名字]".format(sys.argv[0]))

if len(sys.argv) != 6:
    printHelp()
    sys.exit()

if __name__ =="__main__":
    printHelp()

PicCovered=sys.argv[1]
key=int(sys.argv[2])
Wighth=int(sys.argv[3])
Hight=int(sys.argv[4])
jpeg=extrac.jio.read(PicCovered)
Plain=extrac.extra(jpeg,key,Hight*Wighth)

img=np.zeros((Hight,Wighth,3),dtype=int)

for i in range(0,Wighth):
    for j in range(0,Hight):
        if Plain[i*Wighth+Hight] == "1":
            img[i][j]=[0,0,0]
        else :
            img[i][j]=[255,255,255]
cv2.imwrite(sys.argv[6],img)
